﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    public class Base_dal<T> where T:class
    {
        public Model1 Model
        {
            get
            {
                return new Model1();
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public List<T> select(Expression<Func<T,Boolean>> expression)
        {
            return Model.Set<T>().Where(expression).ToList();

        }
        /// <summary>
        /// 单个查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public T selectread(int id)
        {
            return Model.Set<T>().Find(id);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int add(T info)
        {
            Model.Set<T>().Add(info);
            return Model.SaveChanges();
        }
        public int delete(T info)
        {
            Model.Set<T>().Remove(info);
            return Model.SaveChanges();
        }
    }
}
